//
//  AVPlayerManager.h
//  PlayerSample
//
//  Created by lingqineng on 2017/9/6.
//  Copyright © 2017年 lingqineng. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
/**
 *  播放模式枚举
 */
typedef NS_ENUM(NSUInteger, AVPlayerMode) {
    /**
     *  单曲循环
     */
    AVPlayerModeTrackLoop,
    /**
     *  列表循环
     */
    AVPlayerModeListLoop,
    /**
     *  随机播放
     */
    AVPlayerModeRandom,
};

@protocol AVPlayerDelegate <NSObject>
/**
 *  曲目播放完成通知
 *
 */
@optional
- (void)trackPlayDidEnd;
/**
 *  播放进度
 */
-(void)timeRunAndTime:(double)runTime andValue:(NSString *)value andScale:(CGFloat)scale;

@end

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>


@interface AVPlayerManager : NSObject

/** 当前索引*/
@property (nonatomic, assign) NSInteger currentIndex;
/** 是否当前属于播放状态 */
@property (nonatomic, assign) BOOL isPlaying;
/** 总时长 */
@property (nonatomic, assign) CGFloat allTime;
/** 当前播放时间 */
@property (nonatomic, assign) CGFloat currentTime;
/** 自定义avplayer的播放器 */
@property (nonatomic, strong) AVPlayer * player;
/** 当前播放的avItem */
@property (nonatomic, strong) AVPlayerItem * currentMusicItem;
/** 判断是否为收藏夹曲目 */
@property (nonatomic, assign) BOOL isFavorite;
/** 播放代理 */
@property (nonatomic, weak) id<AVPlayerDelegate> delegate;

/**
 *  初始化音乐播放器的单例
 *
 *  @return 单例manager
 */
+( AVPlayerManager *)manager;
/**
 *  重置音乐manager
 */
- (void)resetAudio;
/**
 *  初始化音乐播放manager
 */
- (void)setAVPlayerURL:(NSURL*)url;
/**
 *  播放当前音乐
 */
- (void)play;
/**
 *  暂停当前音乐
 */
- (void)pause;
/**
 *  上一首
 */
- (void)previous;
/**
 *  下一首
 */
- (void)next;
/**
 *  跳转到指定播放时间
 */
- (void)seekToTimeInterval:(double)currentTime;
/**
 *  裁剪音频
 */
+ (void)cutAudioStartTime:(CGFloat)source endTime:(CGFloat)end withPath:(NSString *)path completed:(void (^)(NSString *successPath))completed;
/**
 *  拆分音频
 */
+ (void)splitAudioTime:(CGFloat)source withPath:(NSString *)path completed:(void (^)(NSString *path1, NSString *path2))completed;
/**
 *  合并音频
 */
+ (void)mergeAudios:(NSArray *)paths destnation:(NSString *)outputPath completed:(void (^)(NSString *successPath))completed ;
/**
 *  保存临时文件目录
 */
+ (NSString *)getTmpRecordName:(NSString *)name;
/**
 *  wav转换为mp3
 */
+ (void)convenrtToMp3WithResult:(NSString *)originalPath outPath:(NSString *)outPath completed:(void (^)(NSString *successPath))completed;
/**
 *  转换为wav
 */
+ (void)convertM4aToWav:(NSString *)originalPath outPath:(NSString *)outPath success:(void (^)(NSString *successPath))completed;
/**
 *  转换为m4a
 */
+ (void)convertToM4a:(NSString *)originalPath outPath:(NSString *)outPath success:(void (^)(NSString *successPath))completed;
+(void) convertAudio:(NSURL*)url outputURL:(NSURL*)outputURL completed:(void (^)(NSString *successPath))completed;
@end

